﻿@model _2022_2_28.Areas.StudentArea.Models.Students.UserMessage
<div class="row">
    <div class="col-sm-6 col-sm-offset-2">
        <form method="post">
            <div class="form-group">
                @Html.HiddenFor(m => m.Id)
                @Html.HiddenFor(m => m.Photo)
            </div>
            <div class="form-group">
                <label for="Name">姓名:</label>
                @Html.TextBoxFor(m =>m.Name,new{@class="form-control"})
                <span>@Html.ValidationMessageFor(m=>m.Name)</span>
            </div>
            <div class="form-group">
                @{
                    var year = new List<SelectListItem>();
                    for (int i = 1970; i <= DateTime.Now.Year; i++)
                    {
                        if (Model.Year == i)
                            year.Add(
                            new SelectListItem(i.ToString(), i.ToString(), true));
                        else
                            year.Add(new SelectListItem(i.ToString(), i.ToString()));
                    }

                    var month = new List<SelectListItem>();
                    for (int i = 1; i <= 12; i++)
                    {
                        if (Model.Month == i)
                        {
                            month.Add(new SelectListItem(i.ToString(), i.ToString(), true));
                        }
                        else
                            month.Add(new SelectListItem(i.ToString(), i.ToString()));
                    }

                    var day = new List<SelectListItem>();
                    for (int i = 1; i <= 31; i++)
                    {
                        if (Model.Date == i)
                        {
                            day.Add(new SelectListItem(i.ToString(), i.ToString(), true));
                        }
                        else
                        {
                            day.Add(new SelectListItem(i.ToString(), i.ToString()));
                        }
                    }

                }

                @Html.DropDownList("Year",@year,new{onchange=""})
                @Html.DropDownList("Month",@month,new{onchange=""})
                @Html.DropDownList("Day",@day)
                <select name="Date" id="Date">
                </select>

            </div>


        </form>
    </div>
</div>
@section Scripts
{
<script src="~/lib/jquery/jquery.validate.js"></script>
<script src="~/lib/jquery/jquery.validate.unobtrusive.js"></script>
<script>
     //1. 如何获取月份的值
    var month = document.querySelector("#Month").value;
    var year = document.querySelector("#Year").value;
    
    if(month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
    {
        $("#Date").empty();
        for(let i = 1 ; i <= 31;i++){
            var ele = document.createElement("option");
            ele.setAttribute("value",i.toString());
            ele.innerText = i.toString();
            document.querySelector("#Date").appendChild(ele);
        }
    }
    else if(month == 4 || month == 6 || month == 9 || month == 11 )
    {
        $("#Date").empty();
        for(let i = 1 ; i <= 30;i++){
            var ele = document.createElement("option");
            ele.setAttribute("value",i.toString());
            ele.innerText = i.toString();
            document.querySelector("#Date").appendChild(ele);
        }
    }
    else
    {
        if((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
        {
            $("#Date").empty();
            for(let i = 1 ; i <= 29;i++){
                var ele = document.createElement("option");
                ele.setAttribute("value",i.toString());
                ele.innerText = i.toString();
                document.querySelector("#Date").appendChild(ele);
            }
        }
        else{
            $("#Date").empty();
            for(let i = 1 ; i <= 29;i++){
                var ele = document.createElement("option");
                ele.setAttribute("value",i.toString());
                ele.innerText = i.toString();
                document.querySelector("#Date").appendChild(ele);
            }
        }
    }
</script>
}